package com.sharemarking.wa.platform.mapper;

import com.sharemarking.wa.common.entity.Order;
import com.sharemarking.wa.platform.dto.address.AddressListDto;
import com.sharemarking.wa.platform.dto.produceWaste.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author dxy
 */
@Repository
public interface ProduceWasteMapper {
    @Select("SELECT a.id AS wasteId,a.name AS wasteName,a.pic,waste_type_name FROM wa_org_waste a LEFT JOIN sys_org b ON b.id = a.org_id WHERE b.member_id = #{memberId} LIMIT #{pageIndex},#{pageSize}")
    List<WasteListDto> getChooseWasteList(Map map);

    @Select("SELECT COUNT(*) FROM wa_org_waste a LEFT JOIN sys_org b ON b.id = a.org_id WHERE b.member_id = #{memberId}")
    Integer getChooseWasteListTotal(Map map);

//    List<MyOrderListDto> getMyOrderList(Map map);

    Integer getMyOrderListTotal(Map map);

//    @Select("SELECT b.pic,a.waste_id,a.NAME AS wasteName,a.weight AS weight,t.receiveWeight,t.realWeight\n" +
//            "FROM wa_order_details a LEFT JOIN (SELECT waste_id,SUM( real_weight ) AS realWeight,SUM( weight ) AS receiveWeight \n" +
//            "FROM wa_order_details WHERE order_id IN ( SELECT id FROM wa_order WHERE parent_id = #{orderId} ) GROUP BY waste_id,name )t ON a.waste_id = t.waste_id \n" +
//            "LEFT JOIN wa_org_waste b ON a.waste_id = b.id \n" +
//            "WHERE a.order_id = #{orderId} ")
//    List<MyOrderWasteListDto> getMyOrderWasteListByAllOrder(Integer orderId);
//
//    @Select("SELECT b.pic,a.waste_id,a.name AS wasteName,a.weight,b.weight AS receiveWeight ,b.real_weight FROM wa_order_details a \n" +
//            "LEFT JOIN (SELECT waste_id, name,weight,real_weight FROM wa_order_details WHERE order_id = #{orderId} GROUP BY waste_id,name) b ON a.waste_id = b.waste_id \n" +
//            "LEFT JOIN wa_org_waste b ON a.waste_id = b.id "+
//            "WHERE a.order_id = #{parentId}")
//    List<MyOrderWasteListDto> getMyOrderWasteListByChildOrder(@Param("orderId") Integer orderId, @Param("parentId") Integer parentId);


    @Select("SELECT a.waste_id,a.name AS wasteName,a.weight AS receiveWeight,a.real_weight,b.weight,c.pic FROM wa_order_details a " +
            "LEFT JOIN (SELECT waste_id,weight FROM wa_order_details WHERE order_id = #{parentId} )b ON a.waste_id = b.waste_id " +
            "LEFT JOIN wa_org_waste c ON c.id = a.waste_id WHERE order_id = #{orderId}")
    List<com.sharemarking.wa.platform.dto.orderCommon.WasteListDto> getChildOrderList(@Param("orderId") Integer orderId, @Param("parentId") Integer parentId);


    List<OrgListDto> getChooseOrgList(Map map);
    Integer getChooseOrgListTotal(Map map);

    List<DriverListDto> getChooseDriverList(Map map);
    Integer getChooseDriverListTotal(Map map);

    @Select("SELECT a.* FROM wa_order a LEFT JOIN wa_order_details b ON a.id = b.order_id " +
            "WHERE parent_Id = #{orderId} AND waste_id = #{wasteId} LIMIT #{pageIndex},#{pageSize}")
    List<Order> getOrderInfoList(Map map);

    @Select("SELECT COUNT(*) FROM wa_order a LEFT JOIN wa_order_details b ON a.id = b.order_id " +
            "WHERE parent_Id = #{orderId} AND waste_id = #{wasteId}")
    Integer getOrderInfoListTotal(Map map);


    @Select("SELECT a.exam_state FROM wa_org_verify a LEFT JOIN sys_org_member b ON a.org_id = b.org_id " +
            "WHERE b.member_id = #{memberId}")
    Integer isOrgVerify(Integer memberId);

}
